package com.right.netty.codes;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * Created by ding on 2019/1/17.
 */
@Slf4j
public class PackageDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) throws Exception {
        byte[] b =new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(b);
        String d = new String(b);
        log.info("recv data={}",d);
        list.add(d);
    }
}
